CC      = arm-linux-gnueabi-gcc
LD      = arm-linux-gnueabi-ld
AR      = arm-linux-gnueabi-ar
OBJCOPY = arm-linux-gnueabi-objcopy
OBJDUMP = arm-linux-gnueabi-objdump

DIRS = lib arm9 src

objs := $(foreach dir,$(DIRS),$(patsubst %.c,%.o,$(wildcard $(dir)/*.c)))
objs += os/ucos_ii.o
objs += $(foreach dir,$(DIRS),$(patsubst %.s,%.o,$(wildcard $(dir)/*.s)))

INCLUDEDIR 	:= $(shell pwd)/include
CFLAGS 	:= -Wall -O2 -o
CPPFLAGS   	:=  -I$(INCLUDEDIR) -g -c -fno-stack-protector

#-nostdinc 
ucos.bin : $(objs)
	@echo $(objs)
	$(LD) -g -Tucos.lds -o ucos.elf $^ lib/libgcc.a
	$(OBJCOPY) -O binary -S ucos.elf $@
	$(OBJDUMP) -D -m arm  ucos.elf > ucos.dis

%.o:%.c
	${CC} $(CPPFLAGS) $(CFLAGS) $@ $<

%.o:%.s
	${CC} $(CPPFLAGS) $(CFLAGS) $@ $<

clean:
	rm -f  ucos.bin ucos.elf ucos.dis $(objs)
	
test:ucos.bin
	clear
	gnome-terminal --tab -- gdb-multiarch --tui ucos.elf -ex 'target remote localhost:1234' -ex 'layout reg'
	qemu-system-arm -M vexpress-a9 -nographic -kernel ucos.elf -S -s
	
